import $services from "./index";
import { ICondition, IMovie, IResult } from "../typings/interface";
import { SearchResult } from '../typings/types'

export default class MovieServices {
  // 新增电影
  public static async addMovie(movie: IMovie): Promise<IResult<IMovie | string[]>> {
    return await $services.post('/api/movie/add', movie)
  }

  // 删除电影
  public static async deleteMovie(id: string): Promise<IResult<null>> {
    return await $services.delete(`/api/movie/del/${id}`)
  }

  // 修改电影
  public static async updateMovie(movie: IMovie): Promise<IResult<null>> {
    return await $services.put(`/api/movie/update`, movie)
  }

  // 查询电影
  public static async queryMovie(condition: ICondition): Promise<SearchResult<IMovie[]>> {
    return await $services.get(`/api/movie/query?keyWord=${condition.keyWord}&limit=${condition.limit}&page=${condition.page}`)
  }
}